home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / rand.zip / RAND.DOC < prev    next >
Text File  |  1992-08-26  |  4KB  |  125 lines

  1.                       ┌───────────────────────┐
  2.                       │                       │
  3.                       │          RAND         │
  4.                       │    August 27, 1992    │
  5.                       │                       │
  6.                       │       By Ray Sun      │
  7.                       │                       │
  8.                       └───────────────────────┘
  9.  
  10. Files included:  RAND.PAS     - Source code for random unit
  11.                  RAND.TPU     - Turbo Pascal 6 unit for random numbers
  12.                  TYPETEST.PAS - Example for rand unit
  13.                  TYPETEST.EXE - Compiled example for rand unit
  14.                  RAND.DOC     - Documentation for random unit
  15.  
  16. Purpose:  RAND.PAS provides good random numbers for pascal users.  The
  17. numbers provided should show a statistically acceptable amount of runs
  18. and the average of the numbers should approach half of the input
  19. integer i.  I credit a book of whose name I unfortunately cannot
  20. remember for the algorithm used for the rectangularly distributed
  21. random numbers.  I merely implemented the algorithm as a pascal unit
  22. for the public to use.
  23.  
  24. -----------------------------------------------------------------------
  25. Why RAND?
  26.  
  27.      The random numbers provided by Turbo Pascal sometimes have a
  28. tendency to "run," or provide the same "random" number over and over
  29. in succession.  Also, patterns may develop in the numbers.  This is
  30. noticeable in simple programs that rely completely on Pascal's Random
  31. function.  For example, a friend of mine programmed a Spades game in
  32. pascal, but the game was not fair because each player would receive
  33. long runs in one suit and the overall distribution of cards was bad.
  34. For example, one player would receive all the cards from 4 to Queen in
  35. spades, and he would dominate the game.
  36.  
  37. So why RAND?
  38.  
  39.      The RAND unit's random numbers do not have an unacceptable number
  40. of runs, nor is it short of runs.  The numbers should show a
  41. statistically acceptable number of runs (Near the mean).  Therefore,
  42. the numbers the user gets -should- be more random than the random
  43. numbers Turbo Pascal generates.
  44. -----------------------------------------------------------------------
  45. How do I use RAND?
  46.  
  47.      Simple!  Just type:
  48.  
  49. Uses rand;
  50.  
  51. in your pascal source code with the RAND.TPU file accessible by Turbo
  52. Pascal.  Then, in your main program block, include the following
  53. lines:
  54.  
  55. BEGIN
  56.      Initialize;
  57.      ...
  58.      ...
  59.      ...
  60.      x := RandomNumber(i);
  61. END.
  62.  
  63. YOU MUST INCLUDE THE INITIALIZE LINE, OR THE RandomNumber FUNCTION
  64. WILL NOT WORK!
  65.  
  66. If Initialize conflicts with the name of one of your current
  67. procedures, you may rename it to something more convenient, like
  68. InitializeRandom.  The variable x used here may be any variable, as
  69. long as it is defined as any integer type.  The number returned to x
  70. will be a number from 1 to i, where i is the integer input from the
  71. user.
  72.  
  73. Example:
  74.  
  75. Uses rand;
  76.  
  77. Var z : integer;
  78.  
  79. BEGIN
  80.      Initialize;
  81.      For loop := 1 to 1000 do
  82.      begin
  83.           z := RandomNumber(100);
  84.           Writeln(z);
  85.      end;
  86. END.
  87.  
  88. The output here should be 1000 numbers between 1 and 100, hopefully
  89. random.
  90.  
  91. If a further example is needed, see TYPETEST.PAS for a sample program
  92. which integrates this unit.
  93. -----------------------------------------------------------------------
  94. Problems and Questions
  95.  
  96. Are you getting the same number over and over again?
  97.  
  98. * You probably did not use Initialize; in your source code!
  99.  
  100. Are you getting too many or not enough runs?
  101.  
  102. * NEVER include Initialize; inside your loop!  Initialize should be
  103. * one of your first source code lines within the main block, and it
  104. * should stand by itself.  It should never be run more than once, or the
  105. * purpose of the RAND program is defeated!
  106.  
  107. I need a real number between 0 and i instead of an integer.  How can I
  108. do this?
  109.  
  110. * Edit the source code RAND.PAS so that the final statement in the
  111. * Function Randomnumber definition reads:
  112. *
  113. * RandomNumber:=(frac(x/30269.0+y/30307.0+z/30323.0))*i;
  114. *
  115. * (without the * of course!)
  116.  
  117. These numbers aren't random!  What's the deal????
  118.  
  119. * Can't help you on this one...  I think it works, but if not, I just
  120. * dunno...
  121.  
  122. RAND documentation completed.
  123. Typed by Ray Sun
  124. Program and Source Code by Ray Sun
  125.